﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Serialization;
using System.Xml.Serialization;

using GolfSigma.Inventory.Extension;

namespace GolfSigma.Inventory.Model
{
    public class BatchPutTeeTimesRequest : IRequest
    {
        public List<Model.TeeTime> TeeTimes { get; set; }

        public BatchPutTeeTimesRequest() { }
        public BatchPutTeeTimesRequest(List<TeeTime> teeTimes)
        {
            if (teeTimes == null || teeTimes.Count < 1)
                throw new ArgumentNullException("teeTimes", "Must provide a list of tee times to add.");

            TeeTimes = teeTimes;
        }

        #region IRequest Members

        public string HttpVerb
        {
            get { return "POST"; }
        }

        public string HttpPath
        {
            get { return "/teetimes/batch.xml"; }
        }

        public IDictionary<string, string> HttpParameters
        {
            get 
            {
                // Create our result
                IDictionary<string, string> result = new Dictionary<string, string>();

                // Add post params for each tee-time
                for (int i = 0; i < TeeTimes.Count; i++)
                {
                    DictionaryExtension.AddRange(
                        result,
                        TeeTimes[i].GetPostParamters(i + 1)
                        );
                }

                // Return our params
                return result;
            }
        }

        public IDictionary<string, string> HttpHeaders
        {
            get 
            {
                var headers = new Dictionary<string, string>(1);
                headers.Add("x-gsws-method", "POST");

                return headers;
            }
        }

        #endregion
    }

    [XmlRoot("Response")]
    public class BatchPutTeeTimesResponse
    {
        [XmlArray("TeeTimes")]
        public List<TeeTime> TeeTimes { get; set; }

        [XmlElement("ResponseMetadata")]
        public ResponseMetadata ResponseMetadata { get; set; }
    }
}
